package com.ssy.lingxi.platform.manage.controller.content;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.model.vo.PageVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.platform.manage.entity.content.MemberInformation;
import com.ssy.lingxi.platform.manage.model.request.common.CommonIdListRequest;
import com.ssy.lingxi.platform.manage.model.request.common.CommonIdPageRequest;
import com.ssy.lingxi.platform.manage.model.request.common.CommonIdRequest;
import com.ssy.lingxi.platform.manage.model.request.common.CommonStatusRequest;
import com.ssy.lingxi.platform.manage.model.request.content.*;
import com.ssy.lingxi.platform.manage.model.response.*;
import com.ssy.lingxi.platform.manage.service.content.IMemberInformationService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 内容能力-资讯管理
 * @author wyx
 * @version 2.0.0
 * @date 2021-09-28
 */
@RestController
@RequestMapping("/manage/member/information")
public class MemberInformationController extends BaseController {

    @Resource
    private IMemberInformationService memberInformationService;


    /**
     * 资讯列表
     * @param request 请求参数
     * @return 查询结果
     */
    @GetMapping("/page")
    public Wrapper<PageData<MemberInformationPageResponse>> page(@Valid MemberInformationPageRequest request) {
        return memberInformationService.page(request, getSysUser());
    }

    /**
     * 资讯详情
     * @param request 请求参数
     * @return 查询结果
     */
    @GetMapping(value = "/get")
    public Wrapper<MemberInformation> get(@Validated CommonIdRequest request) {
        return memberInformationService.get(request);
    }

    /**
     * 新增资讯
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/add")
    public Wrapper<Void> add(@RequestBody @Validated({MemberInformationRequest.Add.class}) MemberInformationRequest request) {
        return memberInformationService.add(request, getSysUser());
    }

    /**
     * 修改资讯
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/update")
    public Wrapper<Void> update(@RequestBody @Validated({MemberInformationRequest.Update.class}) MemberInformationRequest request) {
        return memberInformationService.update(request, getSysUser());
    }

    /**
     * 上架/下架
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/updateStatus")
    public Wrapper<Void> updateStatus(@RequestBody @Validated({CommonStatusRequest.Shelf.class}) CommonStatusRequest request) {
        return memberInformationService.updateStatus(request, getSysUser());
    }

    /**
     * 删除资讯
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/delete")
    public Wrapper<Void> delete(@RequestBody @Validated CommonIdRequest request) {
        return memberInformationService.delete(request, getSysUser());
    }

    /**
     * 批量删除/上架/下架
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/batch")
    public Wrapper<Void> batch(@RequestBody @Validated MemberInformationBatchRequest request) {
        return memberInformationService.batch(request, getSysUser());
    }

    /**
     * 根据推荐标签获取
     * @param request 请求参数
     * @return 查询结果
     */
    @GetMapping(value = "/findAllByRecommendLabel")
    public Wrapper<List<MemberInformationResponse>> findAllByRecommendLabel(@Valid RecommendLabelRequest request, Long memberId, Long roleId) {
        UserLoginCacheDTO user = new UserLoginCacheDTO();
        user.setMemberId(memberId);
        user.setMemberRoleId(roleId);
        return memberInformationService.findAllByRecommendLabel(request, user);
    }

    /**
     * 最新发布
     * @param memberId 会员id
     * @param roleId   角色id
     * @return 查询结果
     */
    @GetMapping(value = "/latest")
    public Wrapper<List<MemberInformationResponse>> latest(Long memberId, Long roleId) {
        UserLoginCacheDTO user = new UserLoginCacheDTO();
        user.setMemberId(memberId);
        user.setMemberRoleId(roleId);
        return memberInformationService.latest(user);
    }

    /**
     * 最多阅读
     * @param memberId 会员id
     * @param roleId   角色id
     * @return 查询结果
     */
    @GetMapping(value = "/maximumRead")
    public Wrapper<List<MemberInformationResponse>> maximumRead(Long memberId, Long roleId) {
        UserLoginCacheDTO user = new UserLoginCacheDTO();
        user.setMemberId(memberId);
        user.setMemberRoleId(roleId);
        return memberInformationService.maximumRead(user);
    }

    /**
     * 最多收藏
     * @param memberId 会员id
     * @param roleId   角色id
     * @return 查询结果
     */
    @GetMapping(value = "/maximumCollect")
    public Wrapper<List<MemberInformationResponse>> maximumCollect(Long memberId, Long roleId) {
        UserLoginCacheDTO user = new UserLoginCacheDTO();
        user.setMemberId(memberId);
        user.setMemberRoleId(roleId);
        return memberInformationService.maximumCollect(user);
    }

    /**
     * 根据分类获取
     * @param request  请求参数
     * @param memberId 会员id
     * @param roleId   角色id
     * @return 查询结果
     */
    @GetMapping(value = "/findAllByCategory")
    public Wrapper<List<MemberInformationColumnResponse>> findAllByCategory(@Valid CommonIdRequest request, Long memberId, Long roleId) {
        UserLoginCacheDTO user = new UserLoginCacheDTO();
        user.setMemberId(memberId);
        user.setMemberRoleId(roleId);
        return memberInformationService.findAllByCategory(request, user);
    }

    /**
     * 根据栏目获取
     * @param request  请求参数
     * @param memberId 会员id
     * @param roleId   角色id
     * @return 查询结果
     */
    @GetMapping(value = "/pageByColumnLabel")
    public Wrapper<PageData<MemberInformationResponse>> pageByColumnLabel(@Valid CommonIdPageRequest request, Long memberId, Long roleId) {
        UserLoginCacheDTO user = new UserLoginCacheDTO();
        user.setMemberId(memberId);
        user.setMemberRoleId(roleId);
        return memberInformationService.pageByColumnLabel(request, user);
    }

    /**
     * 资讯栏目
     * @param memberId 会员id
     * @param roleId   角色id
     * @return 查询结果
     */
    @GetMapping(value = "/informationColumn")
    public Wrapper<List<MemberInformationColumnResponse>> informationColumn(Long memberId, Long roleId) {
        UserLoginCacheDTO user = new UserLoginCacheDTO();
        user.setMemberId(memberId);
        user.setMemberRoleId(roleId);
        return memberInformationService.informationColumn(user);
    }

    /**
     * 搜索
     * @param request  请求参数
     * @param memberId 会员id
     * @param roleId   角色id
     * @return 查询结果
     */
    @GetMapping("/search")
    public Wrapper<PageData<MemberInformationResponse>> search(@Valid ContentInformationSearchRequest request, Long memberId, Long roleId) {
        UserLoginCacheDTO user = new UserLoginCacheDTO();
        user.setMemberId(memberId);
        user.setMemberRoleId(roleId);
        return memberInformationService.search(request, user);
    }

    /**
     * 根据ID获取
     * @param request 请求参数
     * @return 查询结果
     */
    @GetMapping(value = "/findById")
    public Wrapper<MemberInformationResponse> findById(@Valid CommonIdRequest request) {
        return memberInformationService.findById(request, isLogin() ? getSysUser() : null);
    }

    /**
     * 根据ID集合获取
     * @param request 请求参数
     * @return 查询结果
     */
    @GetMapping(value = "/findByIdIn")
    public Wrapper<List<MemberInformationListResponse>> findByIdIn(@Valid CommonIdListRequest request) {
        return memberInformationService.findByIdIn(request, getSysUser());
    }

    /**
     * 同类资讯
     * @param request  请求参数
     * @param memberId 会员id
     * @param roleId   角色id
     * @return 查询结果
     */
    @GetMapping(value = "/related")
    public Wrapper<List<MemberInformationResponse>> related(@Valid CommonIdRequest request, Long memberId, Long roleId) {
        UserLoginCacheDTO user = new UserLoginCacheDTO();
        user.setMemberId(memberId);
        user.setMemberRoleId(roleId);
        return memberInformationService.related(request, user);
    }

    /**
     * 收藏/取消收藏
     * @param request 请求参数
     * @return 查询结果
     */
    @PostMapping(value = "/collect")
    public Wrapper<Void> collect(@RequestBody @Validated CollectRequest request) {
        return memberInformationService.collect(request, getSysUser());
    }

    /**
     * 收藏列表
     * @param request 请求参数
     * @return 查询结果
     */
    @GetMapping(value = "/collectList")
    public Wrapper<PageData<ContentInformationResponse>> collectList(PageVO request) {
        return memberInformationService.collectList(request, getSysUser());
    }

    /**
     * 列表（装修）
     * @param request 请求参数
     * @return 查询结果
     */
    @GetMapping("/listAdorn")
    public Wrapper<PageData<MemberInformationListAdornResponse>> listAdorn(@Valid ContentInformationListAdornRequest request) {
        return memberInformationService.listAdorn(request, getSysUser());
    }
}
